var Imp = JavaImporter(
                    Packages.java.lang,
                    Packages.java.io,
                    Packages.java.util,
                    Packages.com.hz.actor,
                    Packages.com.hz.main,
                    Packages.cn.dunn.world.utils,
                    Packages.com.hz.map,
                    Packages.com.hz.ui,
                    Packages.com.hz.core,
                    Packages.com.hz.common,
                    Packages.com.hz.net,
                    Packages.com.google.gson,
                    Packages.java.util.concurrent
                            );
with(Imp){
    var cmd = {
        battleDelay:1200,
        mapConfig:{
            "迎客殿":{mapId:4,x:30,y:4,name:"迎客殿"},
            "风之森林":{mapId:901,x:27,y:3,name:"风之森林"},
            "神剑广场":{mapId:16,x:3,y:44,name:"神剑广场"},
            "镇妖塔":{mapId:11,x:6,y:25,name:"镇妖塔"},
            "世界之门":{mapId:4,x:30,y:4,name:"世界之门"},
            "世界之门西方":{mapId:900,x:8,y:19,name:"世界之门"},
            "新生的城市":{mapId:905,x:11,y:22,name:"新生的城市"},
            "亡者之地":{mapId:902,x:30,y:23,name:"亡者之地"},
            "起源之地":{mapId:905,x:10,y:16,name:"起源之地"},
            "蜀山后山":{mapId:17,x:16,y:9,name:"蜀山后山"},
            "月牙山脚":{mapId:22,x:6,y:28,name:"月牙山脚"},
            "月牙山":{mapId:23,x:9,y:31,name:"月牙山"},
            "月牙山洞":{mapId:293,x:6,y:5,name:"月牙山洞"},
            "赤炎戈壁":{mapId:820,x:17,y:4,name:"赤炎戈壁"},
            "沙漠营地":{mapId:819,x:16,y:5,name:"沙漠营地"},
            "熔岩地狱一层":{mapId:821,x:10,y:4,name:"熔岩地狱一层"},
            "熔岩地狱二层":{mapId:822,x:5,y:22,name:"熔岩地狱二层"},
            "熔岩地狱三层":{mapId:823,x:5,y:14,name:"熔岩地狱三层"},
            "封印墓穴二层":{mapId:915,x:6,y:6,name:"封印墓穴二层"},
            "二层墓穴内堂":{mapId:916,x:14,y:5,name:"二层墓穴内堂"},
            "封印墓地三层":{mapId:917,x:3,y:10,name:"封印墓地三层"},
            "古墓二层":{mapId:814,x:33,y:18,name:"古墓二层"},
            "古墓三层":{mapId:815,x:19,y:25,name:"古墓三层"},
            "主墓室":{mapId:818,x:18,y:25,name:"主墓室"},
            "野蛮冰原":{mapId:921,x:6,y:5,name:"野蛮冰原"},
            "绝望冰原":{mapId:920,x:35,y:34,name:"绝望冰原"},
            "寒冰洞穴一层":{mapId:922,x:5,y:6,name:"寒冰洞穴一层"},
            "寒冰洞穴二层":{mapId:923,x:35,y:24,name:"寒冰洞穴二层"},
            "寒冰洞穴三层":{mapId:924,x:13,y:25,name:"寒冰洞穴三层"},
            "远古森林":{mapId:926,x:24,y:4,name:"远古森林"},
            "远古森林深处":{mapId:927,x:4,y:25,name:"远古森林深处"},
            "黑月之塔一层":{mapId:928,x:6,y:5,name:"黑月之塔一层"},
            "黑月之塔二层":{mapId:929,x:4,y:27,name:"黑月之塔二层"},
            "黑月之塔三层":{mapId:930,x:17,y:34,name:"黑月之塔三层"},
            "紫云山":{mapId:826,x:12,y:29,name:"紫云山"},
            "新月古镇":{mapId:5,x:5,y:5,name:"新月古镇"},
            "圣域":{mapId:263,x:30,y:27,name:"圣域"},
            "血烟营地":{mapId:301,x:6,y:29,name:"血烟营地"},
            "精灵之森林":{mapId:254,x:25,y:2,name:"精灵之森林"},
            "精灵森林":{mapId:251,x:32,y:7,name:"精灵森林"},
            "精灵森林深处":{mapId:908,x:39,y:4,name:"精灵森林深处"},
            "森林核心":{mapId:909,x:31,y:29,name:"森林核心"},
            "五蛇山":{mapId:24,x:5,y:28,name:"五蛇山"},
            "月牙山巅":{mapId:27,x:7,y:23,name:"月牙山巅"},
            "太阳之城":{mapId:906,x:8,y:11,name:"太阳之城"},
            "精灵之森":{mapId:254,x:25,y:2,name:"精灵之森"},
            "邪灵圣殿":{mapId:904,x:2,y:22,name:"邪灵圣殿"},
            "恐惧山谷":{mapId:903,x:3,y:29,name:"恐惧山谷"}
        },

        missionTest:function(){
            var _this = this;
            _.each(GameWorld.myPlayer.missionList, function(mission){
                if(mission){
                    _this.log(mission.name);
                }
            });
        },
        safeBattle:function(){
            this.battleDelay = 1200;
        },
        fastBattle:function(){
            this.battleDelay = 800;
        },
        centerHint:function(content){
            for(var i = 0; i < 100; i++){

                this.delay(100);
                this.run(function(){
                    GameCanvas.g.setColor(16776960);
                    GameCanvas.g.drawString(content, GameCanvas.SCREEN_WIDTH / 2, GameCanvas.SCREEN_HEIGHT / 2, 17);
                });
            }
            
        },
        flushPlayer:function(){
            var ex = new Exchanger();
            this.run(function(){
                // _.each(GameWorld.myPlayer.missionList, function(item){
                //     GameWorld.myPlayer.deleteMission(item.id);
                // });
                // MsgHandler.waitForRequest(MsgHandler.createPlayerEnterMsg(GameWorld.getPlayerID(), GameWorld.strImgCheck), 90, 180);
                MsgHandler.waitForRequest(MsgHandler.createWorldDataReflashMsg());
                
                ex.exchange(null);
            });
            ex.exchange(null);
        },
        skipScene:function(){
            var _this = this;
            new Thread(function(){
                while(true){
                    _this.run(function(){
                        if(GameCanvas.battleAni && GameCanvas.battleAni.battlePanel){
                            core.doMenuAction(GameCanvas.battleAni.battlePanel, 932);//跳过动画
                        }
                    });
                    _this.delay(200);
                }
            }).start();
            
            
        },
        /**
         *
         * 分配属性点
         * attrs:数组格式,分配的方式
         *      第一个元素:力量
         *      第二个元素:体质
         *      第三个元素:敏捷
         *      第四个元素:智力
         *      第五个元素:感知
         * 
         *
         */
        init:function(config){
            
            //GameWorld.doGetItemSuit(GameWorld.myPlayer.getBagAllEquip());//初始化背包
            var _this = this;
            GameWorld.OPEN_SKILLSHOP_ALERT_FIRST = false;
            //
            if(config.attrConfig){
                core.listener("CP_CHANGE", function(){
                    if(GameWorld.myPlayer.cp > 10){
                        _this.log("---------加点----------");
                        var total = _.reduce(config.attrConfig, function(num1, num2){return num1 + num2;});
                        var mul = parseInt(GameWorld.myPlayer.cp / total);
                        if(mul == 0){
                            _this.log("属性点不够,加点失败!");
                            return;
                        }else{
                            _this.allocAttrPoint(_.map(config.attrConfig, function(num){ return num * mul}));
                        }

                        
                    }
                });
            }

            core.listener("map", function(){
                if(GameWorld.gameMap){
                    _this.alert("地图ID:"+GameWorld.gameMap.getMapID()+" 地图名称:" + GameWorld.gameMap.name);
                }else{
                    _this.alert("无法获取地图");
                }
            });

           



        },
        player:function(){
            return GameWorld.myPlayer;
        },
        /**
         * 输出背包物品
         */
        outPag:function(){
            var _this = this;
            var items = _this.getPagItems();
            _.each(items, function(item){
                _this.log(item.name);
            });
        },
        /**
         * 输出NPC 名字
         */
        outNpc:function(){
            var _this = this;
            _this.run(function(){
                _.each(GameWorld.getNPCList(), function(npc){
                    if(npc){
                        //if((npc.getName() == "雷恩长老") && npc.isVisible() && npc.isEnable()){
                            _this.log("[" + npc.getName() + "]");
                        //    _this.log(npc.getGx()+"|"+npc.getGy());

                        //    if (!npc.missions) {
                        //        NPC.doNpc(npc);//获取任务数据
                        //    }
                        //    if(npc.missions && !npc.missions.isEmpty()){
                        //        var missions = npc.missions.toArray();
                        //        _this.log("-------任务--------");
                        //        _.each(missions, function(mission){
                        //            _this.log(mission.name);
                        //        });
                        //        _this.log("-------任务--------");
                        //    }
                        //
                        //
                        //}
                        
                    }
                });
            });
        },
        getLoginToken:function(username, password){
            var loginUrl = MsgHandler.getSocketLoginUrl();
            loginUrl = loginUrl.substring("socket://".length);
            var urlArr = loginUrl.split(":");
            var host = urlArr[0];
            var port = parseInt(urlArr[1]);
            var loginTokenJson = NetUtils.read("http://world.asst.tech:88/game/protocol/loginToken?accountNumber="+username+"&password="+password+"&host="+host+"&port=" + port);
            var loginTokenMap = new Gson().fromJson(loginTokenJson, Class.forName("java.util.Map"));
            return {
                key:loginTokenMap.get("key"),
                sessionId:loginTokenMap.get("sessionId")
            }
        },
        areaTest:function(){
            var _this = this;
            _.each(ServerInfo.gameAreaList.toArray(), function(server){
                _this.log("~" + server.getLineList().get(0).sockUrl + "|" + server.id + "|" + server.name);
            });
        },
        /**
         * 登陆
         */
        doLogin:function(username, password, serverId, roleId){
            var _this = this;
            var ex = new Exchanger();
            _this.run(function(){
                GameWorld.tempUsername = username;
                GameWorld.tempPassword = password;
                GameWorld.doLoginServer(0);

                //-------------------------


                // var server = _.find(ServerInfo.gameAreaList.toArray(), function(server){
                //     return server.id == serverId;
                // });
                // server = server.getLineList().get(0);//登陆当前区的第一个线
                // UIAction.doPlayerListMsg(null, server, true);


                // var player = _.find(GameCanvas.allPlayerList.toArray(), function(player){
                //     return player.getId() == roleId;
                // });
                // if(player){
                //     GameWorld.myPlayer = player;
                //     MsgHandler.waitForRequest(MsgHandler.createPlayerEnterMsg(roleId, GameWorld.strImgCheck), 90, 180);
                //     GameCanvas.stageCounter++;
                // }


                ex.exchange(null);
            });
            ex.exchange(null);


            // return;
            _this.delay(2000);
            ex = new Exchanger();
            _this.run(function(){
                var server = _.find(ServerInfo.gameAreaList.toArray(), function(server){
                    return server.id == serverId;
                });
                server = server.getLineList().get(0);//登陆当前区的第一个线
                UIAction.doPlayerListMsg(null, server, true);
                ex.exchange(null);
            });
            ex.exchange(null);
            _this.delay(2000);
            ex = new Exchanger();
            _this.run(function(){
                var player = _.find(GameCanvas.allPlayerList.toArray(), function(player){
                    return player.getId() == roleId;
                });
                if(player){
                    GameWorld.myPlayer = player;
                    MsgHandler.waitForRequest(MsgHandler.createPlayerEnterMsg(roleId, GameWorld.strImgCheck), 90, 180);
                    GameCanvas.stageCounter++;
                }
                ex.exchange(null);
            });
            ex.exchange(null);
        },
        //打开组队自动接受
        openAutoAccept:function(){
            var _this = this;
            var ex = new Exchanger();
            _this.run(function(){
                var setting = GameWorld.myPlayer.getSetting();
                setting |= 2;
                GameWorld.myPlayer.setSetting(setting);
                MsgHandler.waitForRequest(MsgHandler.createChangeSettingMessgae(setting));
                ex.exchange(null);
            });
            ex.exchange(null);
            
        },
        //关闭组队自动接受
        closeAutoAccept:function(){
            var _this = this;
            var ex = new Exchanger();
            _this.run(function(){
                var setting = GameWorld.myPlayer.getSetting();
                setting |= 2;
                setting -= 2;
                GameWorld.myPlayer.setSetting(setting);
                MsgHandler.waitForRequest(MsgHandler.createChangeSettingMessgae(setting));
                ex.exchange(null);
            });
            ex.exchange(null);
            
        },
        /**
         * 组队申请
         */
        joinTeam:function(leaderId){
            var _this = this;
            while(GameWorld.myPlayer.getLeaderID() != leaderId){
                _this.run(function(){
                    MsgHandler.addSyncMessage(MsgHandler.createInviteTeamMsg(2, leaderId));
                });
                _this.delay(2000);
            }
        },
        /**
         * 等待组员加入
         */
        waitJoinTeam:function(members){
            var _this = this;
            while(true){
                if(GameWorld.myPlayer.getMembers()){
                    var memberArr = GameWorld.myPlayer.getMembers().toArray();
                    if(GameWorld.myPlayer.getMembers().size() == members.size()-1){
                    //校验是否有其他在队伍里
                    // var memberIds = _.map(memberArr, function(memebr){
                    //     return memebr.getId();
                    // });
                    // for(var i = 0; i< memberArr.length; i++){
                    //     if(members.indexOf(memberArr[i].getId())){
                    //     }
                    // }
                        break;
                    }
                }
                
                _this.delay(2000);
            }
        },
        //获取装备职业
        equips:function(){
            var _this = this;
            var items = _this.getAllEquip();
            _.each(items, function(item){
                if(item && item.getInfo() && item.getInfo().startsWith("适合")){
                    var info = item.getInfo();
                    info = info.match(/\/c(\S*)\/p/)[1];//正则提取中间部分
                    info = info.substring(6);
                    System.err.println("ttx:" + info);
                    // android.util.Log("ttx", "ttx:" + item.getInfo());
                    // _this.log(item.name + "|"+ item.round + "|" + item.getInfo());
                }
            });
        },
        onLineDraw:function(name){
            var ex = new Exchanger();
            var _this = this;
            _this.run(function(){
                if(MsgHandler.waitForRequest(new Message(11109))) {
                    var v1 = MsgHandler.getReceiveMsg();
                    if(v1 == null) {
                        ex.exchange(null);
                        return;
                    }
                    var v2 = v1.getByte();
                    if(v2 < 0) {
                        UIHandler.alertMessage(v1.getString());
                        ex.exchange(null);
                        return;
                    }
                    if(v2 == 1) {
                        ex.exchange(null);
                        return;
                    }          
                    ex.exchange(MsgHandler.processAddItemMsg(v1, 2));
                    return;
                }
                _this.closeAll();
            });
            var fullName = ex.exchange(null);
            return fullName?fullName.indexOf(name) != -1:false;
        },
        pollMail:function(){
            var _this = this;
            _this.run(function(){
                
                var poll = function(mail){
                    if(!MsgHandler.waitForRequest(MsgHandler.createMailDetailMsg(mail.id))) {
                        return;
                    }
                    var message = MsgHandler.getReceiveMsg();
                    if(message == null) {
                        return;
                    }

                    Mail.fromBytes(message, mail);

                    if(!mail.isHasReqMoney(null)){
                        Mail.doAttachItemMsg(mail, null);
                    }
                }

                var arr = Mail.doMailListMsg(18,125,1);
                _.each(arr[0].toArray(), poll);


                arr = Mail.doMailListMsg(8,125,1);
                _.each(arr[0].toArray(), poll);
                
                _this.closeAllUI();

            });
            
        },

        test:function(){
            var _this = this;
            _this.log("==========monsterList============");
            _.each(GameWorld.monsterList.values().toArray(), function(m){
                // _this.log(m.getId() + "|" + m.getName());
                _this.log(m.getGx() + "|" + m.getGy());
            });
            _this.log("==========monsterGroupList============" + GameWorld.monsterGroupList.size());
            _.each(GameWorld.monsterGroupList.values().toArray(), function(group){//获取所有的怪物组
                if(group){
                    var monsters = _.filter(group.monsters, function(id){return id!=0});//怪物怪物组中的怪物
                    monsters = _.map(monsters, function(id){
                        return GameWorld.getMonster(id);//根据ID 获取怪物
                    });
                    
                    _this.log(group.groupId);
                    _.each(monsters, function(m){
                        // _this.log(m.getName() +"|" +m.getId());
                        // _this.log(m.getGx() +"|" +m.getGy());
                    });
                    // _this.log(new Gson().toJson(group.npcs));
                }
                    
            });
            var npcs = GameWorld.getNPCList();
            _this.log("==========getNPCList============");
            npcs = _.filter(npcs, function(npc){return npc != null});
            var mission = _.find(_this.player().missionList, function(mission){return mission.name == "破敌"})
            _.each(npcs, function(npc){
                if(npc &&  npc.getName() == "妖尊者" && npc.menuBattle && npc.battleReqMissionID){
                    _this.log("--------------");
                    var mission = _.find(_this.player().missionList, function(mission){return mission.name == "破敌"})
                    //_this.run(function(){
                    //    Mission.doAcceptMissionMsg(GameWorld.myPlayer, npc, mission);
                    //})
                    _this.log(npc.talkDetail);
                    _this.log(_this.toJson(npc.menuBattle));
                    _this.log(_this.toJson(npc.battleID));
                }
                // _this.log(npc.getName() + "|" + npc.battleID[0]);
            });
            _this.run(function(){
                GameWorld.toBattle(133, true);
                
            })
            _this.log("-->a " + mission.getId());
            _this.log("-->a " + mission.acceptBattleID);
            _this.log("-->s " + mission.submitCondition.length);
            //_this.log(":::" + _this.toJson(GameWorld.getMonster(316)));
        },
        toJson:function(obj){
            return new Gson().toJson(obj);
        },
        run:function(fun){
            var _run = new Runnable({run:fun});
            HANDLER.put(_run);
        },
        /**
         * 关闭所有UI
         */
        closeAllUI:function(){
            UIHandler.closeAllUI();
        },
        closeAll:function(){
            UIHandler.closeAllUI();
        },
        /**
         * 弹窗消息
         */
        alert:function(message){
            UIHandler.alertMessage(String.valueOf(message));
        },
        prompt:function(message){
            WorldMessage.addPromptMsg(message);
        },
        waitAlert:function(title, content){
            return UIHandler.waitForTwiceSureUI(title, content) == 10;
        },
        /**
         * 输出到系统聊天
         */
        log:function(message){
            ChatMsg.addChatSystemMsg(message);
        },
        /**
         * 移动
         */
        move:function(x, y){
            var ex = new Exchanger();
            this.run(function(){
                GameWorld.myPlayer.setPosition(x*24, y*24);
                MsgHandler.syncMoveTo();
                ex.exchange(null);
            });
            ex.exchange(null); 
        },
        toCity:function(){
            var _this = this;
            var ex = new Exchanger();
            this.run(function(){
                var city = City.doViewCityInfo(GameWorld.myPlayer.getId());
                City.doEnterCity(city.getMasterId());
                ex.exchange(null);
            });
            ex.exchange(null);
            _this.delay(2000);
            
            
        },
        /**
         * 延时
         * millisecond:延时的时间(毫秒)
         */
        delay:function(millisecond){
            Thread.sleep(millisecond);
        },
        /**
         * 传送
         * mapName:地图名称
         */
        jumpMap:function(mapName){
            var _this = this;
            var point = _this.mapConfig[mapName];
            var ex = new Exchanger();
            _this.run(function(){
                GameWorld.doJumpMap(point.mapId, point.x, point.y);

            });
            while(GameWorld.gameMap.name != point.name){
                Thread.sleep(200);
            }
            Thread.sleep(2000);
        },

        login:function(name){
            var player = _.find(GameCanvas.playerlist, function(item){
                return item && item.getName() == name;
            })
            if(player){
                GameWorld.myPlayer = player;
                MsgHandler.waitForRequest(MsgHandler.createPlayerEnterMsg(player.getId(), "abc"), 90, 180);
            }
            
        },

        logout:function(){
            var _this = this;
            _this.run(function(){
                GameWorld.doLogOutMsg(3, true);
                // GameWorld.doLogOutMsg(1, false);
            });
        },
        reLogin:function(){
            var _this = this;
            var ex = new Exchanger();
            new Thread(function(){
                //TODO hook优化
                var playerName = GameWorld.myPlayer.getName();
                _this.run(function(){_this.logout();});
                _this.delay(3000);
                _this.run(function(){_this.login(playerName);});
                _this.delay(3000);
                ex.exchange(false); 
            }).start();
            ex.exchange(null);
        },
        /**
         * 输出当前地图信息
         */
        gameMap:function(){
            var gamemap = GameWorld.gameMap;
            this.log("地图ID:"+gamemap.getMapID()+",地图名字:" + gamemap.name);
        },
        unListenerBattle:function(){
            core.unListener("FIGHT_START");
            core.unListener("NEXT_ROUND");
            core.unListener("FIGHT_END");
        },
        listenerBattle:function(start, next, end){
            var _this = this;
            start && core.listener("FIGHT_START",function(){
                start();
            });
            next && core.listener("NEXT_ROUND",function(){
                next();
            });
            end && core.listener("FIGHT_END",function(){
               _this.unListenerBattle();
                end();
            });
        },
        /**
         * 分配属性点
         * attrs:数组格式,分配的方式
         *      第一个元素:力量
         *      第二个元素:体质
         *      第三个元素:敏捷
         *      第四个元素:智力
         *      第五个元素:感知
         * 
         */
        allocAttrPoint:function(attrs){
            var _this = this;
            var  message = new Message(11003);
            var length  = _.filter(attrs, function(num){return num > 0}).length;
            message.putByte(length);
            _.each(attrs, function(attr, i){
                if(attr > 0){
                    message.putShort(i + 6);
                    message.putInt(attr);
                }
            });
            MsgHandler.waitForRequest(message);
        },

        fastBattleUpdate:function(){
            var _this = this;
            new Thread(function(){
                while(true){
                    _this.run(function(){
                        if(GameCanvas.battleAni != null && GameCanvas.battleAni.battle != null){
                            MsgHandler.sendRequest(MsgHandler.createBattleUpdate(GameCanvas.battleAni.battle.round));
                            _this.log("fastBattleUpdate");
                        }
                    });
                    
                    _this.delay(200);
                }
            }).start();
            
        },
        _doTeamBattle:function(start, next, end){
             var _this = this;
            _this.listenerBattle(function(){
                // _this.log("战斗开始");
                _this.log("开始的HP:" + GameWorld.myPlayer.hp);
                start && start();
                core.doMenuAction(GameCanvas.battleAni.battlePanel, 6);//开启自动战斗
                // new Thread(function () {
                //     // Thread.sleep(_this.battleDelay);
                //     while(GameCanvas.battleAni != null && GameCanvas.battleAni.battlePanel != null && !GameCanvas.battleAni.battle.isBattleFinish()){
                //         _this.run(function(){
                //             MsgHandler.sendRequest(MsgHandler.createBattleUpdate(GameCanvas.battleAni.battle.round));
                //         });
                //         Thread.sleep(100);
                //         _this.log("实时获取战斗状态");
                //     }

                //     _this.log("实时获取战斗结束");
                //     //Thread.sleep(100);
                    
                // }).start();

            },function(){
                _this.log("下一个回合");
                next && next();
                // new Thread(function () {
                //     // Thread.sleep(_this.battleDelay);
                //     Thread.sleep(100);
                //     core.doMenuAction(GameCanvas.battleAni.battlePanel, 932);//跳过动画
                // }).start();
                
            },function(){
                _this.log("战斗结束");
                //TODO 低血保护
                if((GameWorld.myPlayer.hp / GameWorld.myPlayer.get(29)) < 0.5){
                    _this.quickAddHP();    
                }
                end && end();
            }
            );
        },
        /**
         * 战斗
         */
        _doBattle:function(start, next, end){
            var _this = this;
            //组队模式
            if(GameWorld.myPlayer.isInTeam()){
                _this.log("组队模式!");
                _this._doTeamBattle(start, next, end);
                return;
            }
            
            _this.listenerBattle(function(){
                // _this.log("战斗开始");
                _this.log("开始的HP:" + GameWorld.myPlayer.hp);
                start && start();
                core.doMenuAction(GameCanvas.battleAni.battlePanel, 6);//开启自动战斗

            },function(){
                _this.log("下一个回合");
                next && next();
                new Thread(function () {
                    // Thread.sleep(_this.battleDelay);
                    Thread.sleep(100);
                    core.doMenuAction(GameCanvas.battleAni.battlePanel, 932);//跳过动画
                }).start();
                
            },function(){
                //TODO 低血保护
                if((GameWorld.myPlayer.hp / GameWorld.myPlayer.get(29)) < 0.5){
                    _this.quickAddHP();    
                }
                end && end();
            }
            );
        },
        learnSkill:function(npcName, menuName, skillName, level){
            var _this = this;
            var ex = new Exchanger();
            var npcs = GameWorld.getNPCList();
             _.each(npcs, function(npc){
                if (npc.isVisible() && npc.isEnable() && (npc.getName() == npcName)) {
                    _this.run(function(){
                        NPC.doNpc(npc);//获取任务数据
                        // var index = npc.menuTeacher.indexOf(new String(menuName));
                        _.find(npc.menuTeacher, function(menu, index){
                            if(menu == menuName){
                                var teacherId = npc.teacherId[index];
                                GameWorld.openShopSkill(teacherId);
                                var topUI = UIHandler.getTopUI();
                                var obj = topUI.getObj();
                                var skills = obj.getPageObjList();
                                var map = obj.object;
                                _.find(skills.toArray(), function(skill){
                                    if(skill.name == skillName){
                                        var learned = Skill.doLearnSkill(topUI, _this.player(), skill);
                                        while(learned && learned.level <= level){
                                            learned = Skill.doLearnSkill(topUI, _this.player(), learned);
                                        }
                                        if(!learned){
                                            _this.log("学习失败");
                                        }
                                    }
                                    return skill.name == skillName;
                                });
                            }
                            return menu == menuName;
                        });
                        _this.closeAllUI();
                        ex.exchange(null);
                    });
                    
                }
            });
            
            ex.exchange(null);
        },
        /**
         * 接取任务
         * npcName:npc名称
         * missionName:任务名称
         */
        acceptMission:function(npcName, missionName){
            var _this = this;
            var ex = new Exchanger();
            var delayTime = 0;
            _this.run(function(){
                var result = null;
                var missionNpc = null;
                var npcs = GameWorld.getNPCList();
                if (npcs  && npcs.length > 0) {
                    _.each(npcs, function(npc){
                        if (npc.isVisible() && npc.isEnable() && (npc.getName() == npcName)) {
                            if (!npc.missions) {
                                NPC.doNpc(npc);//获取任务数据
                            }
                            if(npc.missions && !npc.missions.isEmpty()){
                                var missions = npc.missions.toArray();
                                var mission = _.find(missions, function(m){
                                    return m.name == missionName;
                                });
                                if(mission){
                                    result = mission;
                                    missionNpc = npc;
                                }
                            }
                            return;
                        }
                    });
                }

                if(!result){
                    ex.exchange(null);
                    return;
                }
                MsgHandler.waitForRequest(MsgHandler.createWorldDataReflashMsg());
                //接任务时
                if(result.acceptBattleID){
                    _this._doBattle(null, null, function(){
                        ex.exchange(null);
                    });
                    Mission.doAcceptMissionMsg(GameWorld.myPlayer, missionNpc, result);
                }else if(result.acceptJumpMapID){
                    delayTime = 2000;
                    Mission.doAcceptMissionMsg(GameWorld.myPlayer, missionNpc, result);
                    ex.exchange(null);
                }else{
                    Mission.doAcceptMissionMsg(GameWorld.myPlayer, missionNpc, result);
                    ex.exchange(result);
                }     
                UIHandler.closeAllUI();
                _this.log("接取任务完成:" + missionName);
            })
            if(delayTime > 0){
                _this.delay(delayTime);
            }
            return ex.exchange(null);
            
        },
        npcJumpMap:function(npcName, menuName){
            var _this = this;
            var npcs = GameWorld.getNPCList();
            npcs = _.filter(npcs, function(npc){return npc != null});
            var index = -1;
            var npc = _.find(npcs, function(npc){
                if(npc.getName() == npcName && npc.menuJumpMap && npc.menuJumpMap.length > 0){
                    for(var i = 0; i < npc.menuJumpMap.length; i++){
                        if(npc.menuJumpMap[i] == menuName){
                            index = i;
                            break;
                        }
                    }
                    if(index != -1){
                        return true;
                    }
                }
                return false;
            });
            if(!npc || index == -1){
                _this.log("没有找到NPC 传送菜单");
                ex.exchange(null);
                return;
            }
            GameWorld.doJumpMap(npc.jumpMapID[index], npc.jumpMapGx[index], npc.jumpMapGy[index]);
        },
        /**
         * npc战斗
         * npcName:npc名称
         * menuName:菜单名称
         */
        npcBattle:function(npcName, menuName){
            var _this = this;
            var ex = new Exchanger();
            _this.run(function(){
                var npcs = GameWorld.getNPCList();
                npcs = _.filter(npcs, function(npc){return npc != null});
                var index = -1;
                var npc = _.find(npcs, function(npc){
                    if(npc.getName() == npcName && npc.menuBattle && npc.menuBattle.length > 0){
                        for(var i = 0; i < npc.menuBattle.length; i++){
                            if(npc.menuBattle[i] == menuName){
                                index = i;
                                break;
                            }
                        }
                        if(index != -1){
                            return true;
                        }
                    }
                    return false;
                });
                if(!npc || index == -1){
                    _this.log("没有找到NPC 战斗菜单");
                    ex.exchange(null);
                    return;
                }
                NPC.doNpc(npc);//获取任务数据
                var battleID = npc.battleID[index];
                GameWorld.toBattle(battleID, false);
                _this._doBattle(null, null, function(){
                    ex.exchange(null);
                });
                
            });
            ex.exchange(null);
        },
        /**
         * 放弃任务
         * missionName:任务名称
         */
        abandonMission:function(missionName){
            var _this = this;
            _this.run(function(){
                _.each(GameWorld.myPlayer.missionList, function(mission){
                    if(mission && mission.name && (mission.name == missionName)){
                        Mission.doDeleteMissionMsg(GameWorld.myPlayer, mission);
                        UIHandler.closeAllUI();
                        _this.log("成功放弃任务:"+missionName);
                    }
                });
            })
        },
        /**
         * 完成任务
         * missionName:任务名称
         * itenName:奖励道具名称
         */
        finishMission:function(missionName, itemName){
            var _this = this;

 
            var ex = new Exchanger();
            _this.run(function(){

                var mission = _.find(GameWorld.myPlayer.missionList, function(m){return m && m.name == missionName});

                // if(GameWorld.gameMap || GameWorld.gameMap.getMapId() != mission.submitJumpMapID){
                //     GameWorld.doJumpMap(mission.submitJumpMapID,mission.submitJumpMapGx,mission.submitJumpMapGy);
                // }
                var submitResult = false;
                if(!mission){
                    ex.exchange(submitResult);
                    return;
                }
                MsgHandler.waitForRequest(MsgHandler.createWorldDataReflashMsg());
                var npc = GameWorld.getNpcByID(mission.npcId);
                if(mission.selectItems && mission.selectItems.length > 0 && itemName){
                    var item = _.find(mission.selectItems, function(item){return item.name == itemName});
                    if(item){
                       submitResult  = Mission.doSubmitMissionMsg(GameWorld.myPlayer, npc, mission, item);    
                    }
                }else{
                    _this.log(npc);
                    submitResult = Mission.doSubmitMissionMsg(GameWorld.myPlayer, npc, mission, null);
                    
                }
                

                UIHandler.closeAllUI();
                ex.exchange(submitResult);

                // if (npcs  && npcs.length > 0) {
                //     _.each(npcs, function(npc){
                //         if (npc.getName() == npcName) {
                //             if (!npc.missions) {
                //                 NPC.doNpc(npc);//获取任务数据
                //             }
                //             if(npc.missions && !npc.missions.isEmpty()){
                //                 var arr = npc.missions.toArray();
                //                 _.each(arr, function(mission){
                //                     _this.log(mission.name);
                //                     if (mission.name == missionName) {                       
                //                         result = true;      
                //                     }
                //                 })
                //             }
                //             return;
                //         }
                //     });
                // }

                

            });
            if(!ex.exchange(null)){
                throw "任务提交失败";
            }
        },
        /**
         * 任务寻路
         */
        missionAutoMove:function(missionName){
            var _this = this;
            _this.run(function(){
                var mission = _.find(GameWorld.myPlayer.missionList, function(m){return m && m.name == missionName});
                Mission.doMissionAutoPathMsg(mission.getId());
                
            });
            while(!GameWorld.myPlayer.isAutoMove()){
                Thread.sleep(500);
            }
            Thread.sleep(1200);
            _this.alert("任务寻路完成..");
            

        },
        /**
         * 兑换CDK
         */
        specialCode:function(code){
            var _this = this;
            var ex = new Exchanger();

            _this.run(function(){
                GameWorld.doSpecialCode(code);
                ex.exchange(null);
            });

            ex.exchange(null);
        },
        /**
         * 真实移动
         */
        realMove:function(x, y){
            var _this = this;
            var ex = new Exchanger();
            var flag = true;
            while(flag){
                 _this.run(function(){
                    GameWorld.myPlayer.clearAutoMoveList();
                    GameWorld.myPlayer.autoMoveControlList.addElement(Control.createMoveTo(GameWorld.myPlayer.getId(), x, y));
                    if(GameWorld.myPlayer.getGx() == x && GameWorld.myPlayer.getGy() == y){
                        // ex.exchange(null);
                        flag = false;
                    }
                });
                Thread.sleep(500);
            }
           
            // ex.exchange(null);
        },
        /**
         * 查找NPC
         */
        findFirstNpc:function(ncpName){
            var npcs = GameWorld.getNPCList();
            return _.find(npcs, function(npc){return npc && npc.getName() == ncpName && npc.isVisible() && npc.isEnable();});
        },
        /**
         * 查找怪物
         */
        findMonster:function(monsterNames){
            var _this = this;
             var _monsterGroups = _.map(GameWorld.monsterGroupList.values().toArray(), function(group){
                if(group && group.groupId){
                    var monsters = _.filter(group.monsters, function(id){return id!=0});//怪物怪物组中的怪物ID
                    monsters = _.map(monsters, function(id){
                        return GameWorld.getMonster(id);//根据ID 获取怪物
                    });
                    var monster = _.find(monsters, function(monster){
                        //return monster.getName() == monsterName;
                        return _.find(monsterNames, function(monsterName){
                            return monster.getName() == monsterName;
                        })
                        //return monsterNames.indexOf(monster.getName()) != -1;
                    });
                    if(monster && group.groupId){
                        return group;
                    }else{
                        return null;
                    }
                }
                return null;
            });    
            _monsterGroups = _.filter(_monsterGroups, function(monsterGroup){
                return monsterGroup != null;
            });
            var npcs = GameWorld.getNPCList();
            return _.find(npcs, function(npc){
                if(npc && npc.isVisible() && npc.isEnable() && npc.battleID && npc.battleID[0]){
                    var ok = _.find(_monsterGroups, function(monsterGroup){
                        return monsterGroup.groupId == npc.battleID[0];
                    });
                    if(ok){
                        return true;
                    }
                    return false;
                }
                return false;
            });
        },
        /**
         * bug  当打一只怪 建议直接取任务 //TODO
         * [{name:"里面的名字",count:2}]
         */
        killMonster:function(monsterArr){
            var _this = this;
            try{         
                while(_.find(monsterArr, function(m){return m.count > 0})){
                    _this.doKillMonster(monsterArr);
                    
                    if(!GameWorld.myPlayer.isInTeam()){
                        _this.delay(3000);
                    }else{
                        //TODO 任务完成条件中怪物数量什么时候更新?
                        //TODO MsgHandler.parseBattleNormalReward 12506 更新任务杀怪数量状态
                        // _this.delay(5000);
                    }
                }

                // if(!GameWorld.myPlayer.isInTeam()){
                //     _this.delay(3000);
                // }
            }catch(e){
                _this.log(e);
            }
        },
        /**
         * 优化根据名称查找ID  最终根据ID 打怪
         * 无限击杀怪物 一直到获取的物品达到条件为止
         * monsterName:怪物名称
         * itemName:杀怪物获得的任务物品名称
         * count:数量
         */
        killMonsterWithItem:function(monsterNames, itemName, count){
            var _this = this;
            var condition = function(){
                var items = PlayerBag.getPagItemVector(GameWorld.myPlayer).toArray();
                var items = _.filter(items,function(item){ return item.name == itemName})
                if(items.length == 0){
                    return true;
                }
                var totalNum = _.reduce(items, function(item, item1){
                    return item.quantity + item1.quantity;
                }, {quantity:0});
                return totalNum < count;
            }
            if(condition()){
                core.listener("FIGHT_START",function(){
                    _this.log("FIGHT_START..");
                    core.doMenuAction(GameCanvas.battleAni.battlePanel, 6);//开启自动战斗
                });
                core.listener("NEXT_ROUND",function(){
                    // new Thread(function () {
                    //     Thread.sleep(_this.battleDelay);
                    //     core.doMenuAction(GameCanvas.battleAni.battlePanel, 932);//跳过动画
                    // }).start();
                    //core.doMenuAction(GameCanvas.battleAni.battlePanel, 932);//跳过动画
                });
                core.listener("FIGHT_END",function(){
                //    Thread.sleep(2000);
                        
                });
            }
            

            while(condition()){
                var monster = _this.findMonster(monsterNames);
                if(monster){
                    _this.realMove(monster.getGx(), monster.getGy());
                    
                    // _this.move(monster.getGx(), monster.getGy());
                    //Thread.sleep(500);
                    while(GameCanvas.battleAni != null){
                        Thread.sleep(500);
                    }

                    var ex = new Exchanger();
                    _this.run(function(){
                        MsgHandler.waitForRequest(MsgHandler.createWorldDataReflashMsg());
                        ex.exchange(null);
                    });
                    ex.exchange(null);
                    // _this.log("");
                    // GameWorld.myPlayer.clearAutoMoveList();
                    _this.closeAll();
                }
            }
            _this.unListenerBattle();
            GameWorld.myPlayer.clearAutoMoveList();
        },
        doKillMonster:function(monsterArr){
            var _this = this;
             var ex = new Exchanger();
            
            _this.run(function(){
                var killMonster = _.find(monsterArr, function(m){return m.count > 0});
                if(!killMonster){
                    ex.exchange(null);
                    return;
                }
                var monsterGroup = _.find(GameWorld.monsterGroupList.values().toArray(), function(group){
                    if(group && group.groupId){
                        var monsters = _.filter(group.monsters, function(id){return id!=0});//怪物怪物组中的怪物ID
                        monsters = _.map(monsters, function(id){
                            return GameWorld.getMonster(id);//根据ID 获取怪物
                        });
                        var monster = _.find(monsters, function(monster){
                            return monster.getName() == killMonster.name;
                        });
                        if(monster){
                            return true;
                        }else{
                            return false;
                        }
                    }
                });
                if(monsterGroup){
                    GameWorld.toBattle(monsterGroup.groupId, false);
                    _this._doBattle(function(){
                        
                    },function(){

                    },function(){
                        _this.log("战斗完毕!!!!");
                        _this.log(GameCanvas.battleAni);
                        _this.log(GameCanvas.battleAni.getBattle());
                        // if(GameCanvas.battleAni){
                        //     //TODO
                        //     ex.exchange(true); 
                        //     return;
                        // }
                        if(core.get().toString() == "true"){
                            //TODO 组队模式 默认成功
                            if(GameWorld.myPlayer.isInTeam()){
                                _this.log("战斗完毕!!!!--组队模式!");
                                _.each(GameCanvas.battleAni.getBattle().playerList, function(player){
                                    if(player){
                                        _.each(monsterArr, function(m){
                                            if(player.getName() == m.name){
                                                _this.log(m.name + "|" + m.count);
                                                m.count--;
                                            }
                                        });                   
                                    }
                                })

                                // MsgHandler.waitForRequest(MsgHandler.createWorldDataMessage(64, false), 90, 180);
                                //计算打怪个数
                                // var monsterMap = _.groupBy(monsters, function(monster){return monster.getName()});
                                // _.each(monsterArr, function(m){
                                //     if(monsterMap[m.name]){
                                //         m.count -= monsterMap[m.name].length;
                                //     }
                                // });
                            }else{
                                var battle = GameCanvas.battleAni.getBattle();
                                var monsterIds = _.filter(battle.getMonsterGroup().monsters, function(m){return m > 0});
                                var isSurvivals = _.filter(battle.playerList, function(player){
                                    if(player){
                                        return _.contains(monsterIds, player.getId()) && player.hp > 0;
                                    }else{
                                        return false;
                                    }
                                });
                                
                                if(isSurvivals.length > 0){
                                    _this.log("战斗失败: " + isSurvival.getName());
                                }else{

                                    _this.log("战斗胜利");

                                    var monsters = _.filter(GameCanvas.battleAni.getBattle().playerList, function(player){
                                        if(player){                                    
                                            return _.contains(monsterIds, player.getId());
                                        }
                                        return false;
                                    })
                                    //计算打怪个数
                                    var monsterMap = _.groupBy(monsters, function(monster){return monster.getName()});
                                    _.each(monsterArr, function(m){
                                        if(monsterMap[m.name]){
                                            m.count -= monsterMap[m.name].length;
                                        }
                                    });
                                    // _this.log(monsterArr[0].name + "|" + monsterArr[0].count);
                                    
                                }
                            }
                            
                            //TODO 低血保护
                            if((GameWorld.myPlayer.hp / GameWorld.myPlayer.get(29)) < 0.5){
                                _this.quickAddHP();    
                            }
                            ex.exchange(true); 
                        }else{

                            new Thread(function(){
                               //TODO hook优化
                                _this.delay(3000);
                                var playerName = GameWorld.myPlayer.getName();
                                _this.run(function(){_this.logout();});
                                _this.delay(3000);
                                _this.run(function(){_this.login(playerName);});
                                _this.delay(3000);
                                ex.exchange(false); 
                            }).start();
                            
                        }

                        
                        
                        // _this.ok();
                        

                        // _this.log("怪物数量:" + monsters.length);
                        // var isRemaining = _.find(monsters, function(m){return m.count > 0});
                        // if(isRemaining){
                        //     //继续
                        //     _this.doKillMonster(monsterArr, ex);
                        // }else{
                        //     ex.exchange(nulll);
                        // }
                        // _.each(monsters, function(m){
                        //     // _this.log(m.getName()+"|"+m.hp);
                        // });
                    })
                    
                    // new Thread(function(){
                    //     Thread.sleep(500);
                    //     _this.run(function(){
                    //         //_this.alert("-->:" +monsters.length);
                    //         //var group = GameCanvas.battleAni.getBattle().getMonsterGroup();
                    //         // _this.alert(GameWorld.monsterGroupList.get(Integer.valueOf(group.groupId)).monsters.length);
                    //        // _this.alert(GameWorld.monsterList.size());
                            
                    //         // _this.alert(GameWorld.monsterGroupList.get(group.groupId));
                    //         //var info = group.getInfo(); 
                    //         //_this.alert(info);
                    //         // _this.alert(group.monsters);
                    //         // for(var i = 0; i < group.monsters.length; i++){
                    //         //     // _this.log(group.monsters[i]);
                    //         //     if(group.monsters[i] != 0){
                    //         //         // _this.alert("找到第一个怪物位置:" + i);
                    //         //         // _this.log(GameCanvas.battleAni.battlePanel.setCursor);
                    //         //         GameCanvas.battleAni.battlePanel.setCursor(Integer.valueOf(i).byteValue());
                    //         //         GameCanvas.battleAni.battlePanel.doOrderAction(1, null);
                    //         //         break;
                    //         //     }
                    //         // }
                    //     });
                        
                        
                    //     //GameCanvas.battleAni.getBattle().logicRound();
                    // }).start();
                }else{
                    _this.log("未找到合适的怪物:" + killMonster.name);
                    ex.exchange(null);
                }
            });
            var v = ex.exchange(null);
            // if(String.valueOf(v) == false){
            //     //TODO  重新选择角色 进入游戏
            //     _this.delay(60000);
            // }
            _this.log("一轮战斗结束");
        },
        autoAutoSkillPoint:function(){

        },
        /**
         * 穿戴合适的装备并进行修理
         * 对于低等级装备直接出售
         * 对于不合适的武器直接出售
         */
        cuitableEquip:function(){
            var ex = new Exchanger();
            var _this = this;
            _this.run(function(){
                var equipTypes = ["头", "衣", "裤", "肩", "腰带", "背", "鞋", "护手", "链", "戒"];//, "护符", "坐骑", "时装", "单手剑", "双手剑", "单手刀", "双手刀", "轻型武器", "重型武器", "杖", "长柄武器", "轻弩", "重弩", "弓箭", "副手", "任务物品", "战斗道具", "世界道具", "普通道具", "建筑材料", "宝石", "技能书", "宠物", "特殊", "法器", "轻枪", "重枪", "待定义"];
                var allItem = _this.getAllEquip();
                var equipTypeMap = _.groupBy(allItem, function(i){return i.type});
                var arms = _.filter(allItem, function(item){return item.isEquited() && ([10,8].indexOf(item.slotPos) != -1);});
                _.each(arms, function(item){
                    equipTypes[item.type] = "|";
                });
                var repair = false;
                _.each(equipTypes, function(lab, i){
                    
                    if(!lab){
                        return;
                    }
                    var equips = equipTypeMap[i];
                    
                    if(equips && equips.length > 0){
                        _this.log(equips.length);    
                        var equip = _.max(equips, function(item){return Item.isValidEquipRequire(GameWorld.myPlayer, item, null)?item.price:-1});
                        if(!equip.isEquited() && Item.isValidEquipRequire(GameWorld.myPlayer, equip, null)){
                            //进行装配
                            _this.log("推荐装配:"+equip.name);
                            // _this.run(function(){
                                _this._equipItem(equip);
                            // });
                        }
                        if(equip.durability <= 0){
                            //进行修理
                            _this.log(equip.name + ":需要修理");
                            repair = true;
                        }
                        var discards = _.filter(equips, function(item){return !item.isEquited() && Item.isValidEquipRequire(GameWorld.myPlayer, item, null)});
                        if(discards.length > 0){
                            //进行丢弃
                            // _this.run(function(){
                                _.each(discards, function(item){
                                    _this.log("出售:" + item.name);
                                    _this._sellWithMain(item, item.quantity);
                                });
                            // });
                        }
                    }
                    
                });
                if(repair){
                    _this.repairEquip();//进行修理
                    Thread.sleep(1000);
                }

                //出售不需要的武器
                allItem = _this.getAllEquip();
                _.each(allItem, function(item){
                    //可装配, 武器系列, 没有装配
                    if(item.isCanEquip() && item.type >= 13 && item.type <= 24 && !item.isEquited()){
                        _this._sellWithMain(item, item.quantity);
                    }
                });

                ex.exchange(null);
            })
            ex.exchange(null);
            
        },
        /**
         * 出售 主线程中运行
         */
        _sellWithMain:function(item, count){
            MsgHandler.waitForRequest(MsgHandler.createItemShopSell(3, item.id, item.slotPos, count));
            GameWorld.myPlayer.bag.removeBagItemByPos(item.slotPos, count);
        },

        /**
         * 出售装备
         * grade:0(白色),1(绿色,默认),2(蓝色),3(黄色),4(紫色)
         */
        sellRquip:function(grade){
            var _this = this;
            var ex = new Exchanger();
            _this.run(function(){
                var arr = _this.getAllEquip();
                if(!grade){
                    grade = 1;
                }
                arr = _.filter(arr, function(item){return !item.isEquited() && item.grade <= grade});
                _.each(arr, function(item){
                    _this._sellWithMain(item, item.quantity);
                });
                ex.exchange(null);
            });
            ex.exchange(null);
        },
        /**
         * 修理全身装备
         */
        repairEquip:function(){
            var ex = new Exchanger();
            this.run(function(){
                var myPlayer = GameWorld.myPlayer;
                var message = new Message(12019);
                message.putShort(-1);
                if (MsgHandler.waitForRequest(message)) {
                    message = MsgHandler.getReceiveMsg();
                    if (message) {
                        var var0 = message.getInt();
                        myPlayer.setMoneyByType(13, var0);
                        PlayerBag.repairEquip(myPlayer, -1, false);
                        UIHandler.updateWorldIconPoint();
                        UIHandler.alertMessage("身上装备全部修理成功!");
                    }
                }
                ex.exchange(null);
            });
            ex.exchange(null);
            
        },
        /**
         * 获取最小的耐久度
         */
        minDurability:function(){
            var _this = this;
            var arr = _this.getAllEquip();
            arr = _.filter(arr, function(item){return item.isEquited() && item.slotPos != 17 && item.slotPos != 1;});
            arr = _.map(arr, function(item){ 
                _this.log(item.name + "|" + item.durability);
                return item.durability;
                });
            return _.min(arr);
        },
        /**
         * 获取所有装备
         */
        getAllEquip:function(){
            return GameWorld.myPlayer.getBagAllEquip().toArray();
        },
        getPagItems:function(){
            var _this = this;
            return PlayerBag.getPagItemVector(GameWorld.myPlayer).toArray();
        },
        quickAddHP:function(){
            GameWorld.doQuickAddHP(GameWorld.myPlayer);
        },
        /**
         * 使用消耗品
         */
        useConsumableItem:function(itemName){
            var _this = this;
            var ex = new Exchanger();
            _this.run(function(){
                var items = _this.getPagItems();
                var item = _.find(items,function(item){return item?item.name == itemName:false});
                if(item){
                    GameWorld.doWorldUseItemAction(GameWorld.myPlayer, item, false);
                }else{
                    _this.log("找不到使用的物品!");
                }
                ex.exchange(null);
            });
            ex.exchange(null);
            
        },
        /**
         * 装配装备
         * item:需要装配的装备
         */
        _equipItem:function(item){
            GameWorld.doEquipAction(GameWorld.myPlayer, item);
        },
        equip:function(itemName){
            var _this = this;
            _this.run(function(){
                var arr = _this.getAllEquip();
                arr = _.filter(arr, function(item){return !item.isEquited();});
                var item = _.find(arr, function(item){
                    return item.name == itemName;
                });
                if(item){
                    _this._equipItem(item);
                }
            });
            
        }

    }

}